<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *会员列表
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$tabs=array(
	array('op'=>'list','title'=>'平台会员'),
	array('op'=>'merch','title'=>'商户会员'),
	array('op'=>'zhun','title'=>'无粉丝会员'),
);
//会员列表
if($_RQ['op']=='list' || $_RQ['op']=='merch'){
	$params=array();
	$where='g.uniacid = '.$_SESSION['uniacid'];
	$params['uniacid']=$_SESSION['uniacid'];
	if($_RQ['op']=='merch'){
		$where .=" and g.merchid >0";
		$params['merchid >']=0;
	}else{
		$where .=" and g.merchid =0";
		$params['merchid']=0;
	}
	if(!empty($_RQ['name'])){
		$where .=" and g.name LIKE %".trim($_RQ['name'])."%";
		$return['params']['name']=$_RQ['name'];
	}
	if(!empty($_RQ['mid'])){
		$where .=" and g.mid =".intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	if($_RQ['psize']){
		$return['params']['psize']=$_RQ['psize'];
	}
	$psize = $_RQ['psize']?:20;
	$pindex = max(1,intval($_RQ['page']));
	$total='';
	if(isset($_RQ['level'])){
		$where .=" and g.level =".intval($_RQ['level']);
		$return['params']['level']=$_RQ['level'];
	}
	if($_RQ['storeid']){
		$where .=" and g.storeid =".intval($_RQ['storeid']);
		$return['params']['storeid']=$_RQ['storeid'];
	}
	if($_RQ['merchid']){
		$where .=" and g.merchid =".intval($_RQ['merchid']);
		$return['params']['merchid']=$_RQ['merchid'];
	}
	$selectsql='g.id,g.uniacid,g.mid,g.groupid,g.status,g.isblack,g.createtime,g.level,g.storeid,g.merchid';
	//$where .=" and o.nickname !=''";
	$orderby=' ORDER BY g.id DESC';
	$joinparams=array(
		'table'=>'core_members',
		'join'=>' o.id = g.mid',
		'where'=>$where,
		'orderby'=>$orderby,
		'select'=>$selectsql,
		'limit'=>array($pindex,$psize),
		'a'=>'g',
		'b'=>'o',
	);
	$list=pdo_joinlist('jy_weishop_member',$joinparams,$total);
	//$list=pdo_getslice('jy_weishop_member',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		$get_ostitle=get_ostitle();
		foreach($list as $k=>&$item){
			if(!$item['fromuser']){
				$fromuser=pdo_getcolumn('core_members',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['mid']),'fromuser');
				if($fromuser){
					pdo_update('jy_weishop_member',array('fromuser'=>$fromuser),array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['id']));
				}
			}
			$item['member']=cfc('core')->member_show($item['mid']);
			if($item['merchid']){
				$member=model('jy_merch/member')->getdetail($item['merchid'],$item['mid']);
			}else{
				$member=model('core/member')->detail($item['mid'],array('nickname','onemid','credit1','credit2'));
			}
			$item=array_merge($member,$item);
			$item['order_num']=$this->count('order',array('merchid'=>$item['merchid'],'uniacid'=>$_SESSION['uniacid'],'mid'=>$item['mid'],'status'=>array(1,2,3,10)));
			$item['leveltitle']=pdo_getcolumn('jy_weishop_member_level',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['level']),'title')?:'默认会员';
			$from_os=pdo_getcolumn('core_members',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['mid']),'from_os');
			$fans=pdo_get('core_fans',array('type'=>$from_os,'mid'=>$item['mid'],'uniacid'=>$_SESSION['uniacid']),array('type','id','mid','wxgid','aligid','ttgid','baidugid'));
			if(!$fans['wxgid'] && $fans['aligid']){
				pdo_update('core_fans',array('wxgid'=>$fans['aligid']),array('id'=>$fans['id'],'uniacid'=>$_SESSION['uniacid']));
			}
			if(!$fans['wxgid'] && $fans['ttgid']){
				pdo_update('core_fans',array('wxgid'=>$fans['ttgid']),array('id'=>$fans['id'],'uniacid'=>$_SESSION['uniacid']));
			}
			if(!$fans['wxgid'] && $fans['baidugid']){
				pdo_update('core_fans',array('wxgid'=>$fans['baidugid']),array('id'=>$fans['id'],'uniacid'=>$_SESSION['uniacid']));
			}
			$item['os']=$get_ostitle[$fans['type']];
			$item['os']=$item['os']?:'浏览器';
			if($fans['type']!=2){
				$item['wxapptitle']=pdo_getcolumn('core_account_wxapp',array('uniacid'=>$_SESSION['uniacid'],'id'=>$fans['wxgid']),'title');
				$item['wxapptitle']=$item['wxapptitle']?:'无';
			}else{
				$item['wxapptitle']=pdo_getcolumn('core_account_wechat',array('uniacid'=>$_SESSION['uniacid'],'id'=>$fans['wxgid']),'title');
				$item['wxapptitle']=$item['wxapptitle']?:'无';
			}
			$item['ostitle']=$item['os'].'-'.$item['wxapptitle'];
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'export'=>'export',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','tip'=>'[<red>温馨提示</red>]：
		</br>1、关于<red>匿名用户/空白会员</red>的解释：正常认证服务号，没有关闭获取粉丝详细的情况下，同时粉丝要关注公众号，才会弹窗授权获取粉丝昵称头像；可能小程序出现匿名用户的情况居多：原因是：小程序官方不允许首次访问弹窗获取粉丝详细。但是为了上下级的准确性，在访问小程序首页的时候就产生了下级关系！这时候就会出现匿名用户的情况。但是只要这个匿名用户访问了购物车，商品，会员中心等任何页面。就会弹窗获取粉丝信息。这时候匿名用户就会变成带昵称头像的会员了！
		</br>2、【<red>多个昵称,头像一样的会员</red>】？每个公众号，每个小程序（微信/支付宝/头条），都会有自己的唯一粉丝会员，固然就会出现多个雷同会员。
		</br>3、【<red>多个雷同会员如何统一</red>】？1、只需绑定同样的手机号，会员就会统一；2、利用微信开放平台统一粉丝会员（这个方法操作较复杂）；
		</br>4、【<red>多个雷同会员</red>】？所属商户不同，会有不同的会员体系。
		','edit'=>true,'total'=>$total,'psize'=>$psize,'del_one'=>true,'delall'=>true,'list'=>array(
			array('name'=>'mid','title'=>'MID','type'=>'string'),
			array('name'=>'member','title'=>'基本信息','type'=>'member'),
			array('name'=>'ostitle','title'=>'对应前端','type'=>'string'),
			array('name'=>'storeid','title'=>'所属门店','type'=>'select','options'=>'stores'),
			array('name'=>'merchid','title'=>'所属商户','type'=>'select','options'=>'merchs','option_title'=>'merchname'),
			array('name'=>'leveltitle','title'=>'等级','type'=>'string'),
			array('name'=>'groupid','title'=>'分组','type'=>'select','options'=>'groups'),
			array('name'=>'credit1','title'=>'积分','type'=>'string'),
			array('name'=>'credit2','title'=>'余额','type'=>'string'),
			array('name'=>'order_num','title'=>'已支付订单数','type'=>'string'),
			array('name'=>'createtime','title'=>'注册时间','type'=>'time'),
			array('name'=>'isblack','title'=>'加入黑名单','type'=>'switch','set'=>'set'),
		),'action'=>array(
			array('type'=>'modal','op'=>'setstore','title'=>'设置所属门店'),
			array('type'=>'modal','op'=>'recharge','title'=>'充值'),
			array('type'=>'modal','op'=>'cpassword','title'=>'重置密码'),
			array('type'=>'modal','op'=>'formdata','title'=>'表单信息'),
		)),
		'search'=>array(
			array('name'=>'level','width'=>15,'title'=>'等级','type'=>'select','options'=>'levels'),
			
			
			array('type'=>'choose','width'=>15,'title'=>'会员ID','name'=>'mid','action'=>'core/member.get_member/'),
		),
	);
	if($_RQ['op']=='merch'){
		unset($htmls['list']['list'][2]);
		$htmls['search'][]=array('name'=>'merchid','width'=>15,'title'=>'所属商户','type'=>'select','options'=>'merchs','option_title'=>'merchname');
	}else{
		unset($htmls['list']['list'][3]);
		$htmls['search'][]=array('name'=>'storeid','width'=>15,'title'=>'所属门店','type'=>'select','options'=>'stores');
	}
	$return['levels']=$this->getall('member_level',array('merchid'=>0,'uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	//添加默认等级
	$return['levels'][0]=array(
		'id'=>'0',
		'title'=>'默认会员',
		'level'=>0,
		'discount'=>'0',
		'ordermoney'=>'0.00',
		'ordercount'=>'0',
		'status'=>'1',
	);
	$return['groups']=$this->getall('member_group',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['stores']=$this->getall('store',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	if($this->plugin_exists('jy_merch')){
		$jy_merch=true;
	}
	if($jy_merch){
		$return['merchs']=pdo_getall('jy_merch_user',array('uniacid'=>$_SESSION['uniacid']),array('id','merchname'),'id');
	}
	$return['htmls']=$htmls;
	exi($return);
}
//VIP会员列表
if($_RQ['op']=='zhun'){
	$params=array();
	$where='g.uniacid = '.$_SESSION['uniacid'];
	$params['uniacid']=$_SESSION['uniacid'];
	if(!empty($_RQ['name'])){
		$where .=" and g.name LIKE %".trim($_RQ['name'])."%";
		$return['params']['name']=$_RQ['name'];
	}
	if(!empty($_RQ['mid'])){
		$where .=" and g.mid =".intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	if(isset($_RQ['level'])){
		$where .=" and g.level =".intval($_RQ['level']);
		$return['params']['level']=$_RQ['level'];
	}
	$selectsql='g.id,g.uniacid,g.mid,g.groupid,g.status,g.isblack,g.createtime,g.level,g.storeid';
	$where .=" and o.nickname =''";
	$orderby=' ORDER BY g.id DESC';
	$joinparams=array(
		'table'=>'core_members',
		'join'=>' o.id = g.mid',
		'where'=>$where,
		'orderby'=>$orderby,
		'select'=>$selectsql,
		'limit'=>array($pindex,$psize),
		'a'=>'g',
		'b'=>'o',
	);
	$list=pdo_joinlist('jy_weishop_member',$joinparams,$total);
	//$list=pdo_getslice('jy_weishop_member',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as $k=>&$item){
			$item['member']=cfc('core')->member_show($item['mid']);
			$member=model('core/member')->detail($item['mid'],array('nickname','onemid','credit1','credit2'));
			$item=array_merge($member,$item);
			$item['order_num']=$this->count('order',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$item['mid'],'status'=>array(1,2,3,10)));
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'export'=>'export',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','tip'=>'[<red>温馨提示</red>]：
		</br>1、关于<red>匿名用户/空白会员</red>的解释：正常认证服务号，没有关闭获取粉丝详细的情况下，是不会存在匿名用户的；可能小程序出现匿名用户的情况居多：原因是：小程序官方不允许首次访问弹窗获取粉丝详细。但是为了上下级的准确性，在访问小程序首页的时候就产生了下级关系！这时候就会出现匿名用户的情况。但是只要这个匿名用户访问了购物车，商品，会员中心等任何页面。就会弹窗获取粉丝信息。这时候匿名用户就会变成带昵称头像的会员了！
		</br>2、【<red>多个昵称,头像一样的会员</red>】？每个公众号，每个小程序（微信/支付宝/头条），都会有自己的唯一粉丝会员，固然就会出现多个雷同会员。
		</br>2、【<red>多个雷同会员如何统一</red>】？1、只需绑定同样的手机号，会员就会统一；2、利用微信开放平台统一粉丝会员（这个方法操作较复杂）；
		','edit'=>true,'del_one'=>true,'delall'=>true,'list'=>array(
			array('name'=>'mid','title'=>'MID','type'=>'string'),
			array('name'=>'member','title'=>'基本信息','type'=>'member'),
			array('name'=>'storeid','title'=>'所属门店','type'=>'select','options'=>'stores'),
			array('name'=>'level','title'=>'等级','type'=>'select','options'=>'levels'),
			array('name'=>'groupid','title'=>'分组','type'=>'select','options'=>'groups'),
			array('name'=>'credit1','title'=>'积分','type'=>'string'),
			array('name'=>'credit2','title'=>'余额','type'=>'string'),
			array('name'=>'order_num','title'=>'已支付订单数','type'=>'string'),
			array('name'=>'createtime','title'=>'注册时间','type'=>'time'),
			array('name'=>'isblack','title'=>'加入黑名单','type'=>'switch','set'=>'set'),
		),'action'=>array(
			array('type'=>'modal','op'=>'setstore','title'=>'设置所属门店'),
			array('type'=>'href','key'=>'mid','action'=>'core/member.member/recharge','title'=>'充值'),
			array('type'=>'href','key'=>'mid','action'=>'core/member.member/cpassword','title'=>'重置密码'),
			array('type'=>'modal','op'=>'formdata','title'=>'表单信息'),
		)),
		'search'=>array(
			array('name'=>'level','title'=>'等级','type'=>'select','options'=>'levels','width'=>'25'),
			array('type'=>'choose','width'=>15,'title'=>'会员ID','name'=>'mid','action'=>'core/member.get_member/'),
		),
		
	);
	$return['levels']=$this->getall('member_level',array('merchid'=>0,'uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	//添加默认等级
	$return['levels'][0]=array(
		'id'=>'0',
		'title'=>'默认会员',
		'level'=>0,
		'discount'=>'0',
		'ordermoney'=>'0.00',
		'ordercount'=>'0',
		'status'=>'1',
	);
	$return['groups']=$this->getall('member_group',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['stores']=$this->getall('store',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='edit'){
	$return=array();
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_weishop_member',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		$item['order_count']=pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$item['mid'],'status'=>3));
		$sql = "SELECT SUM(price) FROM " . tablename('jy_weishop_order') . " WHERE uniacid=:uniacid AND mid=:mid AND status=3";
		$money = pdo_fetch($sql,array(":uniacid" => $_SESSION['uniacid'],":mid" => $item['mid']));
		$item['order_money']=$money['SUM(price)'];
		$member=model('core/member')->detail($item['mid'],array('nickname','avatar','mobile','realname','from_os'));
		$item['nickname']=$member['nickname'];
		$item['avatar']=$member['avatar'];
		$item['mobile']=$member['mobile'];
		$item['realname']=$member['realname'];
		$item['openid']=pdo_getcolumn('core_fans',array('type'=>$member['from_os'],'mid'=>$item['mid'],'uniacid'=>$_SESSION['uniacid']),'openid');
		$item['oldlevel']=$item['level'];
	}else{
		$item=array();
	}
	$return['item']=$item;
	$return['item']['createtime']=date('Y-m-d H:i:s',$item['createtime']);
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'tabs'=>array(
			array('op'=>'list','title'=>'返回会员列表'),
		),
		'edit_tab'=>true,
		'edits'=>array(
			array(
				'title'=>'基本信息',
				'list'=>array(
					array('type'=>'string','title'=>'会员昵称','name'=>'nickname','help'=>''),
					array('type'=>'copy','title'=>'OPENID','name'=>'openid'),
					array('type'=>'image','title'=>'头像','name'=>'avatar','help'=>''),
					array('type'=>'select','title'=>'会员组','name'=>'groupid','options'=>'group','help'=>''),
					array('type'=>'select','title'=>'会员等级','name'=>'level','options'=>'levels','help'=>''),
					array('name'=>'storeid','title'=>'所属门店','type'=>'select','options'=>'stores'),
					array('type'=>'string','title'=>'真实姓名','name'=>'realname','help'=>''),
					array('type'=>'string','title'=>'手机号','name'=>'mobile','help'=>''),
					array('type'=>'string','title'=>'注册时间','name'=>'createtime','help'=>'','read'=>true),
					array('type'=>'switch','title'=>'加入黑名单','name'=>'isblack','help'=>'设置黑名单后，此会员无法访问商城'),
					
				)
			),
				array(
				'title'=>'交易信息',
				'list'=>array(
					array('type'=>'string','title'=>'成交订单数','name'=>'order_count','help'=>'','read'=>true),
					array('type'=>'string','title'=>'成交额','name'=>'order_money','help'=>'','read'=>true),
				)
			),
		)
	);
	
	$return['group']=pdo_getall('jy_weishop_member_group',array('uniacid'=>$_SESSION['uniacid']));
	$return['levels']=pdo_getall('jy_weishop_member_level',array('merchid'=>0,'uniacid'=>$_SESSION['uniacid']));
	$return['stores']=$this->getall('store',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$data=array(
		'groupid'=>intval($postdata['groupid']),
		'level'=>intval($postdata['level']),
		'isblack'=>intval($postdata['isblack']),
		'storeid'=>intval($postdata['storeid']),
	);
	$member=array(
		'mobile'=>trim($postdata['mobile']),
		'nickname'=>trim($postdata['nickname']),
		'avatar'=>trim($postdata['avatar']),
		'realname'=>trim($postdata['realname']),
	);
	$id=intval($postdata['id']);
	$mid=intval($postdata['mid']);
	if($id){
		if($postdata['oldlevel']!=$postdata['level']){
			$this->model('member')->up_member_level($mid,$postdata['level'],$postdata['merchid'],6);
		}
		pdo_update('jy_weishop_member',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		pdo_update('core_members',$member,array('id'=>$mid,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		pdo_insert('jy_weishop_member',$data);
	}
	exi('操作成功！','','list');
}
if($_RQ['op']=='export'){
	//会员列表
	$where='g.uniacid = '.$_SESSION['uniacid'];
	$params['uniacid']=$_SESSION['uniacid'];
	if(!empty($_RQ['name'])){
		$where .=" and g.name LIKE %".trim($_RQ['name'])."%";
		$return['params']['name']=$_RQ['name'];
	}
	if(!empty($_RQ['mid'])){
		$where .=" and g.mid =".intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	if($_RQ['psize']){
		$return['params']['psize']=$_RQ['psize'];
	}
	$psize =1000;
	$pindex = max(1,intval($_RQ['page']));
	$total='';
	if(isset($_RQ['level'])){
		$where .=" and g.level =".intval($_RQ['level']);
		$return['params']['level']=$_RQ['level'];
	}
	if(isset($_RQ['storeid'])){
		$where .=" and g.storeid =".intval($_RQ['storeid']);
		$return['params']['storeid']=$_RQ['storeid'];
	}
	$selectsql='g.id,g.uniacid,g.mid,g.groupid,g.status,g.isblack,g.createtime,g.level,g.storeid,g.merchid';
	$where .=" and o.nickname !=''";
	$orderby=' ORDER BY g.id DESC';
	$joinparams=array(
		'table'=>'core_members',
		'join'=>' o.id = g.mid',
		'where'=>$where,
		'orderby'=>$orderby,
		'select'=>$selectsql,
		'limit'=>array($pindex,$psize),
		'a'=>'g',
		'b'=>'o',
	);
	$list=pdo_joinlist('jy_weishop_member',$joinparams,$total);
	if($list){
		foreach($list as &$item){
			$item['createtime']=date('Y/m/d H:i:s',$item['createtime']);
			if($item['merchid']){
				$member=model('jy_merch/member')->getdetail($item['merchid'],$item['mid']);
				$item['storetitle']=pdo_getcolumn('jy_merch_user',array('id'=>$item['merchid'],'uniacid'=>$_SESSION['uniacid']),'merchname');
			}else{
				$member=model('core/member')->detail($item['mid'],array('username','nickname','mobile','onemid','credit1','credit2'));
				$item['storetitle']=pdo_getcolumn('jy_weishop_store',array('id'=>$item['storeid'],'uniacid'=>$_SESSION['uniacid']),'title');
			}
			$item=array_merge($member,$item);
			$item['order_num']=$this->count('order',array('merchid'=>$item['merchid'],'uniacid'=>$_SESSION['uniacid'],'mid'=>$item['mid'],'status'=>array(1,2,3,10)));
			$item['leveltitle']=pdo_getcolumn('jy_weishop_member_level',array('id'=>$item['level'],'uniacid'=>$_SESSION['uniacid']),'title');
			$item['grouptitle']=pdo_getcolumn('jy_weishop_member_group',array('id'=>$item['groupid'],'uniacid'=>$_SESSION['uniacid']),'title');
		}
	}
	$header=array(
		'id'=>'会员ID',
		'username'=>'会员账号',
		'nickname'=>'昵称',
		'mobile'=>'手机号',
		'storetitle'=>'所属门店',
		'leveltitle'=>'等级',
		'grouptitle'=>'分组',
		'order_num'=>'已支付订单数',
		'credit1'=>'账户积分',
		'credit2'=>'账户余额',
		'createtime'=>'注册时间',
	);
	model('core/tools')->export2excel($header,$list,'会员数据');
}
if($_RQ['op']=='formdata'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择会员！','error');
	}
	$mid=pdo_getcolumn('jy_weishop_member',array('id'=>$id),'mid');
	$item=pdo_get('core_members',array('id'=>$mid),array('id','diyformdata'));
	$item['diyformdata']=$item['diyformdata']?json_decode($item['diyformdata'],true):array();
	foreach($item['diyformdata'] as &$v){
		if($v['type']==5 && $v['data']){
			$v['data'] = explode(";", $v['data']);
			foreach($v['data'] as $k=>&$i){
				if(empty($v['data'][$k])){
					unset($v['data'][$k]);
				}
			}
		}
	}
	$return['item']=$item;
	$htmls=array(
		'type'=>'look',
		'look'=>array(
			array(
						'title'=>'表单详情',
						'type'=>'array',
						'name'=>'diyformdata',
						'list'=>array(
							array('type'=>'string','name'=>'title','title'=>'表单标题'),	
							array('type'=>'labelarray','name'=>'data','title'=>'表单内容'),	
						),
			)
		),
	);
	$return['htmls']=$htmls;	
	exi($return);
}
if($_RQ['op']=='setstore'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$id=intval($post['id']);
		$update=array(
			'storeid'=>intval($post['storeid']),
		);
		pdo_update('jy_weishop_member',$update,array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
		exi('设置成功！','','//list/');
	}
	$id=intval($_RQ['id']);
	$item=pdo_get('jy_weishop_member',array('id'=>$id),array('storeid','id'));
	$return['item']=$item;	
	$htmls=array(
		'type'=>'edit',
		'desc'=>'绑定门店',
	);
	$htmls['edit']=array(
		array('type'=>'select','title'=>'绑定门店','name'=>'storeid','options'=>'stores'),
	);
	$return['htmls']=$htmls;
	$return['stores']=$this->getall('store',array('uniacid'=>$_SESSION['uniacid']),array('id','title'));	
	exi($return);
}
if($_RQ['op']=='recharge'){
	//充值
	$credit_types=credit_types();
	if($_RQ['postdata']){
		$postdata=get_postdata();
		if(!$postdata['value']){
			exi('请先输入金额/积分！','error');
		}
		if(!$postdata['type']){
			exi('请选择类型！','error');
		}
		$typetitle=$credit_types[$postdata['type']];
		if($postdata['value'] <=0){
			exi($typetitle.'的值不能小于等于0','error');
		}
		if(is_numeric($postdata['value']) === false){	
			exi($typetitle.'的值必须是整数或小数','error');
		}
		if(!isset($postdata['is_add'])){
			exi('请选择增加/减少！','error');
		}
		$mid=intval($postdata['id']);
		$type=trim($postdata['type']);
		$is_add=intval($postdata['is_add']);
		$value=trim($postdata['value']);
		$remark=trim($postdata['remark']);
		$member=pdo_get('core_members',array('id'=>$mid),array('id','nickname','credit1','credit2','credit3','credit4','credit5','credit6'));
		if($is_add==0 && $value>$member['credit'.$type]){
			exi('请减少的['.$typetitle.']不能大于用户拥有的积分！','error');
		}
		//执行操作
		cfc('core')->member_credit($mid,'credit'.$type,$value,$is_add,'core',$remark,'',$_SESSION['uid']);
		exi('操作['.$typetitle.']成功！','','list');
	}
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择会员！','error');
	}
	$mid=pdo_getcolumn('jy_weishop_member',array('id'=>$id),'mid');
	$member=pdo_get('core_members',array('id'=>$mid),array('id','nickname','credit1','credit2','credit2','credit3','credit4','credit5','credit6'));
	$return['item']=$member;
	$return['types']=credit_types();
	$return['is_adds']=array(
		'1'=>'增加',
		'0'=>'减少',
	);
	$htmls=array(
		'type'=>'edit',
		'edit'=>array(
			array('type'=>'string','name'=>'nickname','title'=>'会员昵称','read'=>true),
		),
	);
	foreach($credit_types as $k=>$cv){
		$htmls['edit'][]=array('type'=>'string','name'=>'credit'.$k,'title'=>'当前'.$cv,'read'=>true);
	}
	$htmls['edit'][]=array('type'=>'radio','name'=>'type','title'=>'积分类型','options'=>'types');
	$htmls['edit'][]=array('type'=>'radio','name'=>'is_add','title'=>'增加/减少','options'=>'is_adds');
	$htmls['edit'][]=array('type'=>'string','name'=>'value','title'=>'额度');
	$htmls['edit'][]=array('type'=>'text','name'=>'remark','title'=>'备注');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='cpassword'){
	//
	if($_RQ['postdata']){
		$post=get_postdata();
		$id=intval($post['id']);
		if(!$id){
			exi('请先选择会员！','error');
		}
		if(!$post['password']){
			exi('请设置密码！','error');
		}
		$update=array(
			'salt'=>random(8),
		);
		$update['password']=get_password($post['password'],$update['salt']);
		pdo_update('core_members',$update,array('id'=>intval($post['id'])));
		exi('密码重置成功！','','list');
	}
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择会员！','error');
	}
	$mid=pdo_getcolumn('jy_weishop_member',array('id'=>$id),'mid');
	$item=pdo_get('core_members',array('id'=>$mid),array('id'));
	$htmls=array(
		'type'=>'edit',
		'edit'=>array(
			array('type'=>'password','name'=>'password','title'=>'新密码'),
		),
	);
	$return['htmls']=$htmls;
	$return['item']=$item;
	exi($return);
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_weishop_member',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}
if($_RQ['op']=='set'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择会员！','error');
	}
	$post=get_postdata();
	if(isset($post['isblack'])){
		pdo_update('jy_weishop_member',array('isblack'=>intval($post['isblack'])),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	exi('操作成功！');
}